home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: more problems with qsort
- Date: 27 Feb 1996 15:44:36 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb27084436@qcd.lanl.gov>
- References: <177399702S86.JW1675A@american.edu>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: JW1675A@american.edu's message of Mon, 26 Feb 96 10:44:18 EST
-
- In article <177399702S86.JW1675A@american.edu>
- JW1675A@american.edu (James D. Watson) writes:
-
- <snip>
- JDW: Architecture: SunOS 4.1.3 with ANSI-C compiler.
- JDW:
- JDW: I'm doing some file manipulation and between steps A and B, I
- need to sort.
- JDW: For various reasons, I don't want to popen() to the sort
- utility--I want to
- JDW: use qsort. Here's what I'm doing:
- JDW:
- JDW: get number of lines in the file
- JDW: (char**)malloc with enough room for all lines
- JDW: for each line in the file {
- JDW: (char*)malloc(90) /* 90 is enough room for each line in file */
- JDW: copy each line into the newly malloc()ed space
- JDW: point a (char**) to the newly malloc()ed space
- JDW: }
-
- The above code block does not compile.
-
- JDW:
- JDW: so now I should have "lines" number of pointers to pointers to char,
- JDW: each one pointing to 90 bytes containing a line in the file.
- JDW:
- JDW: So, I call qsort(array[0], lines, 90, compare)
- JDW: where compare is my comparison function -- prepared as discussed
- JDW: in the FAQ. Now all I get are core dumps during the call to qsort().
- JDW: :-)
-
- Please write your code where every function has a `prototype' either
- by inclusion of a standard header (e.g. <stdlib.h>) or directly.
- Write your code using no casts. Get it to a point where the compiler
- does not complain.
-
- Then readup the difference between char** and char[][90] (the FAQ
- should explain this well, and this is the problem with your
- code). Read up the documentation of qsort.
-
- If you still do not understand it, please write the shortest possible
- such code that demonstrates the problem. Then post the resulting code
- if you still have trouble.
-
- JDW:
- JDW: The core dump isn't in my compare routine -- it's somewhere else in
- JDW: the qsort() function according to dbx -- so I'm sure it's a problem
- JDW: setting up my data.
- JDW:
- JDW: Any tips? Much appreciation in advance,
-
- Please take the time to ask the question in a meaningful form so as
- more people can help you.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-